package gold.digger;

import gold.utils.InputUtil;

import java.util.Arrays;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC1685 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int[] getSumAbsoluteDifferences(int[] nums) {
            int n = nums.length;
            int[] dp = new int[n];
            for (int i = n - 2; i >= 0; i--) {
                dp[n - 1] += nums[n - 1] - nums[i];
            }

            for (int i = n - 2; i >= 0; i--) {
                dp[i] = dp[i + 1] + (n - 2 * i - 2) * (nums[i + 1] - nums[i]);
            }

            return dp;
        }
    }

    public void run() {
        Solution solution = new Solution();
        int[] arr = InputUtil.toIntegerArray("[2,3,5]");
        System.out.println(Arrays.toString(solution.getSumAbsoluteDifferences(arr)));
    }

    public static void main(String[] args) throws Exception {
        LC1685 an = new LC1685();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
